/**可拖拽组件 */
export class DragerAssembly {
    id: number;
    name: string;
    typeCode: string;
    iconCSS: string;
    dftHeight: number;
    dftWidth: number;
    dftValue: string;
    dftAttr: any;
    enableAuth: number;
    authFlag: number;
}

/**表单定义 */
export class FormDef {
    formId: number;
    formName: string;
    formDesc: string;
    bizId: number;
    bizName: string;
    procDefId: number;
    procDefName: string;
    customSaveUrl: string;
    formWidth: number;
    fromHeight: number;
    multiVersion: boolean;
    attachmentFlag: boolean;
    displayOrder: number;
    groupName: string;
    validFlag: number;
    createUser: string;
    createTime: string;
    constructor(options: {
        formId?: number,
        formName?: string,
        formDesc?: string,
        bizId?: number,
        bizName?: string,
        procDefId?: number,
        procDefName?: string,
        customSaveUrl?: string,
        formWidth?: number,
        fromHeight?: number,
        multiVersion?: boolean,
        attachmentFlag?: boolean,
        displayOrder?: number,
        validFlag?: number,
        groupName?: string;
        createUser?: string,
        createTime?: string
    } = {}) {
        this.formId = options.formId;
        this.formName = options.formName;
        this.formDesc = options.formDesc;
        this.bizId = options.bizId;
        this.bizName = options.bizName;
        this.procDefId = options.procDefId;
        this.procDefName = options.procDefName;
        this.customSaveUrl = options.customSaveUrl;
        this.formWidth = options.formWidth;
        this.fromHeight = options.fromHeight;
        this.multiVersion = options.multiVersion;
        this.attachmentFlag = options.attachmentFlag;
        this.displayOrder = options.displayOrder;
        this.validFlag = options.validFlag;
        this.groupName = options.groupName;
        this.createUser = options.createUser;
        this.createTime = options.createTime;
    }
}

/**组件 */
export class Assembly {
    id: number;
    name: string;
    labelName: string
    value: any;
    shadow: number;
    controlType: string;
    displayOrder: number;
    formId: number;
    authFlag: number;
    authCode: number;
    configs: AssemblyConfigs;
    attributes: AssemblyStyles;
    validators: AssemblyValidators;
    constructor(options: {
        id?: number,
        name?: string,
        labelName?: string,
        value?: string,
        shadow?: number,
        config?: string;
        controlType?: string,
        displayOrder?: number,
        authFlag?: number,
        authCode?: number,
        formId?: number,
        attrChanged?: boolean,
        configs?: AssemblyConfigs,
        attributes?: AssemblyStyles,
        validators?: AssemblyValidators
    } = {}) {
        this.id = options.id;
        this.name = options.name;
        this.labelName = options.labelName;
        this.value = options.value;
        this.shadow = options.shadow || 0;
        this.displayOrder = options.displayOrder === undefined ? 1 : options.displayOrder;
        this.controlType = options.controlType || '';
        this.formId = options.formId;
        this.authFlag = options.authFlag;
        this.authCode = options.authCode;
        this.configs = options.configs;
        this.attributes = options.attributes;
        this.validators = options.validators;
    }
}

/**样式属性 */
export class AssemblyStyles {
    width: number;
    height: number;
    format: string;
    x: number;
    y: number;
    length: number;
    angle: number;
    color: string;
    fontSize: number;
    fontDirection: string;
    fontColor: string;
    textUnderLine: string;
    textDeleteLine: string;
    textAlign: string;
    borderStyle: string;
    borderRadius: string;
    fontFamily: string;
    fontWeight: string;
    fontStyle: string;
    lineHeight: number;
    maskstyle: any;
    dateFormat: string;
    display: string;
    opts: { key: string, value: string }[] = [];
    style: any;
    constructor(options: {
        width?: number,
        height?: number,
        format?: string,
        x?: number,
        y?: number,
        length?: number,
        angle?: number,
        color?: string,
        fontSize?: number,
        fontDirection?: string,
        fontFamily?: string,
        fontWeight?: string,
        fontStyle?: string,
        fontColor?: string,
        textUnderLine?: string,
        textDeleteLine?: string,
        textAlign?: string,
        borderStyle?: string,
        borderRadius?: string,
        dateFormat?: string,
        lineHeight?: number,
        maskZindex?: number,
        maskstyle?: any,
        display?: string,
        opts?: any,
        style?: any
    } = {}) {
        this.width = options.width;
        this.height = options.height;
        this.x = options.x || 0;
        this.y = options.y || 0;
        this.length = options.length || 0;
        this.angle = options.angle || 0;
        this.color = options.color || 'black';
        this.format = options.format || '';
        this.fontSize = options.fontSize;
        this.fontDirection = options.fontDirection;
        this.fontStyle = options.fontStyle;
        this.fontFamily = options.fontFamily;
        this.fontWeight = options.fontWeight;
        this.textUnderLine = options.textUnderLine;
        this.textDeleteLine = options.textDeleteLine;
        this.textAlign = options.textAlign;
        this.borderStyle = options.borderStyle || "solid";
        this.borderRadius = options.borderRadius || "0";
        this.dateFormat = options.dateFormat;
        this.display = options.display;
        this.maskstyle = options.maskstyle || {};
        this.opts = options.opts || [];
    }
    refreshStyle() {
        this.style = {};
        if (this.fontDirection == 'vertical') {
            this.style['width'] = '1.2em';
            this.style['line-height'] = '1.2em';
            this.style['word-wrap'] == 'break-word';
        } else if (this.fontDirection == 'transverse') {
            this.style['line-height'] = '';
            this.style['width'] = '';
            this.style['word-wrap'] = '';
        }
        if (this.fontSize > 0)
            this.style["font-size"] = this.fontSize + "px";
        if (this.width > 0)
            this.style["width"] = this.width + "px";
        if (this.height > 0)
            this.style["height"] = this.height + "px";
        if (this.fontFamily)
            this.style["font-family"] = this.fontFamily;
        if (this.fontWeight == "1") {
            this.style["font-weight"] = "bold";
        } else if (this.fontWeight == "2") {
            this.style["font-weight"] = "";
        }
        if (this.fontStyle == "1") {
            this.style["font-style"] = "italic";
        } else if (this.fontStyle == "2") {
            this.style["font-style"] = "normal";
        }
        if (this.textUnderLine == "1") {
            this.style["text-decoration"] = "underline";
        }
        if (this.textDeleteLine == "1") {
            this.style["text-decoration"] = "line-through";
        }
        if (this.textUnderLine == "0" && this.textDeleteLine == "0") {
            this.style["text-decoration"] = "none";
        }
        if (this.textAlign != "")
            this.style["text-align"] = this.textAlign;
        this.maskstyle = {}
        if (this.x > 0)
            this.maskstyle["left"] = this.x + "px";
        if (this.y > 0)
            this.maskstyle["top"] = this.y + "px";
        if (this.color != '')
            this.style["color"] = this.color;
        if (this.length > 0) {
            if (1 == this.angle) {
                //水平
                this.style["border-top"] = this.width + "px " + this.borderStyle + " " + this.color;
                this.style["width"] = this.length + "px";
            } else if (2 == this.angle) {
                //垂直
                this.style["border-left"] = this.width + "px " + this.borderStyle + " " + this.color;
                this.style["height"] = this.length + "px";
            }
            this.style["background-color"] = "";
            this.style["color"] = "";
        }
        if (this.borderRadius != "") {
            if (this.borderRadius.indexOf('%') < 0 && this.borderRadius.indexOf('px') < 0) {
                this.style["border-radius"] = this.borderRadius + 'px';
            } else {
                this.style["border-radius"] = this.borderRadius;//兼容百分比的方式
            }
        }
        if(this.display){
            this.style['display'] = this.display;
        }
        this.maskstyle["position"] = "absolute";
    }
}

/**验证属性 */
export class AssemblyValidators {
    required: boolean;
    maxLength: number;
    minLength: number;
    pattern: string;
    constructor(options: {
        required?: boolean;
        maxLength?: number;
        minLength?: number;
        pattern?: string;
    } = {}) {
        this.required = options.required || false;
        this.maxLength = options.maxLength || 0;
        this.minLength = options.minLength || 0;
        this.pattern = options.pattern || "";
    }
}

/**项目配置 */
export class AssemblyConfigs {
    placeholder: string;
    items: string;
    columns: string;
    showTime: number;
    dateFormat: string;
    autocomplete: boolean;//自动补全
    completeURL: string;
    completeSQL: string;
    constructor(options: {
        placeholder?: string;
        items?: string;
        columns?: string;
        showTime?: number;
        dateFormat?: string;
        autocomplete?: boolean;
        completeURL?: string;
        completeSQL?: string;
    } = {}) {
        this.items = options.items;
        this.columns = options.columns;
        this.placeholder = options.placeholder;
        this.showTime = options.showTime;
        this.dateFormat = options.dateFormat;
        this.autocomplete = options.autocomplete;
        this.completeURL = options.completeURL;
        this.completeSQL = options.completeSQL;
    }
}

/**数据集 */
export class FormDataSet {
    constructor(
        public dataSetId?: number,
        public systemId?: number,
        public systemName?: string,
        public systemUrl?: string,
        public expressionType?: string,
        public dataExpression?: string,
        public dataSetName?: string,
        public formId?: number,
        public validFlag?: number
    ) { }
}

/**数据采集 */
export class FormDataPush {
    constructor(
        public dataPushId?: number,
        public systemId?: number,
        public systemName?: string,
        public systemUrl?: string,
        public expressionType?: string,
        public dataExpression?: string,
        public dataPushName?: string,
        public formId?: number,
        public validFlag?: number
    ) { }
}